package com.chandra.pos.web.category.action;

import com.chandra.pos.dao.entity.CategoryEntity;
import com.chandra.pos.service.ProductService;
import com.chandra.pos.web.CRUDAction;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: root
 * Date: 7/8/12
 * Time: 2:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class CategoryAction extends ActionSupport implements CRUDAction {
    private ProductService productService;
    private List<CategoryEntity> listCategory;

    @Override
    public String doHome() {
        return SUCCESS;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doNew() {
        return INPUT;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doDelete() {
        return SUCCESS;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doList() {
        return SUCCESS;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doUpdate() {
        this.addActionMessage("Category "+name+"Successfully updated");

        return SUCCESS;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doEdit() {
        return INPUT;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doSave() {
       CategoryEntity categoryEntity=new CategoryEntity();
       categoryEntity.setName(this.name);
        categoryEntity.setDescription(this.description);
        categoryEntity.setParentId(parentId);
        productService.createCategory(categoryEntity);

        this.addActionMessage("Category "+name+"Successfully created");
        return SUCCESS;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String doSearch() {
        return SUCCESS;  //To change body of implemented methods use File | Settings | File Templates.
    }

    private String name;

    private String description;

    private Long id;

    private Long parentId;

    public ProductService getProductService() {
        return productService;
    }

    public void setProductService(ProductService productService) {
        this.productService = productService;
    }

    public List<CategoryEntity> getListCategory() {
        return listCategory;
    }

    public void setListCategory(List<CategoryEntity> listCategory) {
        this.listCategory = listCategory;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }
}
